package com.callbell.cas.util;

import java.text.MessageFormat;
import java.util.Date;

import com.callbell.cas.sdk.SMSService;
import com.callbell.cas.sdk.impl.LuosimaoSMS;

public class SMSKit {
	private static final int CHECKCODENUM = 4;
    private static final String msgCheckCodeContent = "{0}欢迎使用科贝尔，您的验证码:{1},三分钟内有效。【科贝尔】";
    private static SMSService smsService;
    
    public static SMSService getSmsService() {
        return smsService;
    }

    public static void setSmsService(SMSService smsService) {
        SMSKit.smsService = smsService;
    }
    
    public static String sendRandomCheckCode(String mobile,String accountName) {
        if(null == smsService){
            setSmsService(new LuosimaoSMS());
        }
        String checkCode = RandomCodeGenerator.generateCheckCodeString(CHECKCODENUM);
        String content = MessageFormat.format(msgCheckCodeContent,accountName,checkCode, new Date());
        sendMessage(mobile, content);
        return checkCode;
    }
    
    public static void sendMessage(final String mobile, final String msg) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                smsService.sendSMS(mobile, msg);
            }
        }).run();
    }
    
    public static void main(String[] args) throws InterruptedException {
//        SMSKit.setSmsService(new LuosimaoSMS());
//        String checkCode = SMSKit.sendRandomCheckCode("18620852973","尊敬的用户");
//        System.out.println(checkCode);
    	
    	long start = System.currentTimeMillis();
    	Thread.sleep(180000);
    	long end = System.currentTimeMillis();
    	System.out.println((end - start));
    }
}
